package br.mikhas.db.model;

import java.util.Collection;
import java.util.Collections;

import br.mikhas.util.Assert;

/**
 * Defines a group of fields which belongs to an index
 * 
 * @author Mikhail Domanoski
 * 
 */
public class Index {

	/**
	 * Index fields
	 */
	protected Collection<Field> fields;

	/**
	 * Flags if this field is unique
	 */
	protected boolean unique;

	/**
	 * The index length in bytes
	 */
	protected int length;

	/**
	 * The fields which belongs to the index
	 */
	public Collection<Field> getFields() {
		return Collections.unmodifiableCollection(this.fields);
	}

	/**
	 * Flags if this index is unique
	 */
	public boolean isUnique() {
		return this.unique;
	}

	/**
	 * Checks if this index contains the passed field
	 * 
	 * @param field
	 *            The field to check
	 * @return <tt>true</tt> if this index contains the passed field
	 */
	public boolean containsField(Field field) {
		Assert.notNull(field);
		return fields.contains(field);
	}

	/**
	 * Gets the index length in bytes
	 * 
	 * @return the length
	 */
	public int getLength() {
		return this.length;
	}
}
